# 方法一
class Solution:
    def numberOfBeams(self, bank: List[str]) -> int:
        m, n = len(bank), len(bank[0])
        tem = [0] * m
        for i in range(m):
            for j in range(n):
                if bank[i][j] == "1":
                    tem[i] += 1
        
        ans = 0
        print(tem)
        a, b = 0, 0
        for i in range(m):
            if tem[i] != 0 and a == 0:
                a = tem[i]
            elif tem[i] != 0:
                b = tem[i]
                ans += a * b 
                a = b 
                b = 0
        return ans

# 方法二
class Solution:
    def numberOfBeams(self, bank: List[str]) -> int:
        a, b, res = 0, 0, 0
        for row in bank:
            cnt = row.count("1")
            if cnt > 0:
                a, b = b, cnt
                res += a * b
        return res